package game.Russian;

import java.awt.Color;
import java.util.Random;


public class TetrisBlock extends Matrix{

	//方块矩阵
	private int type=0;//方块图形类型


	private static Random rand=new Random();
	/* 方块图形类型
	 * typ1-type5:
	 *
	 * 1 xxxx   2        3 xxx
	 *   xxxx      oo      oox
	 *   oooo      oo      xoo
	 *   xxxx
	 *
	 * 4 xxx   5 xxx
	 *   ooo     xox
	 *   xxo     ooo
	 */
	public static final int TYPE1=0;
	public static final int TYPE2=1;
	public static final int TYPE3=2;
	public static final int TYPE4=3;
	public static final int TYPE5=4;


	public static TetrisBlock getRandomBlock() {

		int randType=rand.nextInt(TYPE5+1);
		TetrisBlock block=null;
		//处理方块图形，有内容为1，无内容为0.
		switch (randType) {
			case TYPE1:
				block=new TetrisBlock(4,4,TYPE1);
				for(int i=0;i<block.getColumn();i++) {
					block.get()[2][i]=GrapVal;
				}
				return block;
			case TYPE2:
				block=new TetrisBlock(2, 2,TYPE2);
				block.get()[0][0]=block.get()[0][1]=GrapVal;
				block.get()[1][0]=block.get()[1][1]=GrapVal;
				return block;
			case TYPE3:
				block=new TetrisBlock(3, 3,TYPE3);
				block.get()[1][0]=block.get()[1][1]=GrapVal;
				block.get()[2][1]=block.get()[2][2]=GrapVal;
				return block;
			case TYPE4:
				block=new TetrisBlock(3, 3,TYPE4);
				block.get()[1][0]=block.get()[1][1]=GrapVal;
				block.get()[1][2]=block.get()[2][2]=GrapVal;
				return block;
			case TYPE5:
				block=new TetrisBlock(3, 3,TYPE5);
				block.get()[1][1]=block.get()[2][0]=GrapVal;
				block.get()[2][1]=block.get()[2][2]=GrapVal;
				return block;
			default:
				return null;
		}
	}

	public TetrisBlock(int row,int column,int type) {
		super(row,column);
		this.type=type;
	}

	public Color getColor() {
		switch (type) {
			case TYPE1:
				return Color.CYAN;
			case TYPE2:
				return Color.GREEN;
			case TYPE3:
				return Color.RED;
			case TYPE4:
				return Color.YELLOW;
			case TYPE5:
				return Color.BLUE;
			default:
				return null;
		}
	}
}
